﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EPiServer;
using EPiServer.Core;

namespace EPiBoost.Core.Extensions
{
	public static class ContentLoaderExtensions
	{
		public static IEnumerable<IContent> GetSelfAndAncestors(this IContentLoader structure, IContent rootContent, IContent content, string cultureName)
		{
			if (content == null || rootContent == null)
				yield break;

			while (true)
			{
				yield return content;
				if (ContentReference.IsNullOrEmpty(content.ParentLink) || rootContent.ContentLink.CompareToIgnoreWorkID(content.ContentLink))
				{
					yield break;
				}
				content = structure.Get<IContent>(content.ParentLink, LanguageSelector.Fallback(cultureName, true));
			}
		}
	}
}
